<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <base th:href="${#request.getContextPath()}+'/'">
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/admin.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/login.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/images/code.png}" media="all">
    <script type="text/javascript">
        const publicExponent = "[[${publicExponent}]]";
        const modules = "[[${modules}]]";
    </script>
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>后台登录</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-tips" for="LAY-user-login-password"></label>
                <input type="password" name="twoFactorCode" id="LAY-user-login-code" lay-verify="required" placeholder="Google验证码" class="layui-input">
            </div>

            <div class="layui-form-item">
                <button id="login-button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 录</button>
            </div>
        </div>
    </div>

</div>

<script th:src="@{/js/layui/layui.all.js}"></script>
<script src="/admin/js/plugins/RSA.js"></script>
<script src="/admin/js/plugins/Barrett.js"></script>
<script src="/admin/js/plugins/BigInt.js"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['form'], function () {
        // 操作对象
        var form = layui.form
            , $ = layui.jquery;

        if (window != top) {
            top.location.href = location.href;
        }

        // 监听回车键事件
        $(document).on ('keypress', function (event) {
            if (event.key === 'Enter') {
                $('#login-button').click ();
                return false;
            }
        });

        form.on("submit", function (data) {

            // 加密阶段
            // setMaxDigits(260);
            // var pdKey = new RSAKeyPair(publicExponent, "", modules);
            // data.field.password = encryptedString(pdKey, data.field.password);

            $.ajax({
                url: [[${basePath}]] + "/login/valid/user",
                data: data.field,
                sync: false,
                success: function (data) {
                    if (data.success) {
                        window.location.href = [[${basePath}]] + "/";
                        return
                    }
                    else if(data.code == '1001'){
                        layer.msg("Google身份验证码不正确", {time: 1000, icon: 5});
                        return
                    }
                    else if(data.code == '1002'){
                        layer.msg("Google身份验证器KEY失效，请联系管理员", {time: 1000, icon: 5});
                        return
                    }
                    else {
                        layer.msg(data.msg, {time: 1000, icon: 5});
                        return
                    }
                }
            });
            return false;
        });


    });
</script>
</body>
</html>